import Block from "../qbasics/basics/Block";
import Row from "../qbasics/basics/Row";
import Lex from "./Lex";
import StrTo from "../qbasics/utils/StrTo";
import Dict from "./Dict";
export default class LexCore{
    constructor(){
      /*  this.wordr=new Wordr();
        this.word=new Word(this);*/
        this.dict=new Dict();
        this.lex=new Lex(this);
    }

    /**
     *  参数都是 buff
     * @param dataRow
     * @param dataBlock
     * @param linkRow
     */
    loadData(data ){
        // this.init();
        this.dict.loadData(data)
    }

    outData(){
        let buff=this.dict.outData();
        return  buff;
    }


    /**
     * 初始化
     */
    init(){
        this.dict=new Dict();
        // this.addRound(); //目录 可能也不需要、 、


    }

    run(str){
       return this.word.run(str)
    }
    lexRun(ids){
      let   lexs=new Lex(this);
       return lexs.run(ids)
    }

    /**
     * 获取语法 type
     * @param lexTypes
     */
    yaccType(lexTypes){
        let res=new Array();
        for(let i=0;i<lexTypes.length;i++){
            let lexType=lexTypes[i]
            let id=lexType.wordIdKey?lexType.wordIdKey:lexType.wordsId;
            res.push({data:this.findWord(id),type:this.findYaccType(id)})
        }


        return res;

    }



    /**
     * 用ID 获取 文字
     * @param id
     * @returns {string}
     */
    findWord(id){
         let word=  this.word.findWord(id)
       return word;
    }

    /**
     * 获取语法类型
     */
    findYaccType(ids){
        let block=  this.wordr.list[ids];
        let id=0;
        for(let i=0;i<block.list.length;i++){
            let row=block.list[i];
            if(row.isValue(4,"2")){
               id= row.find(1)
            }
        }

      return  this.findWord(id);

    }




    /**
     * 添加一个词
     * 一个或者多个
     */
    addIder(strs,type){
      let   id= this.wordr.findWordId(strs,type);
      return id;
    }
    /**
     * 给一个词添加标记
     */
    iderAddSign(strs,row){
        let   id= this.wordr.findWordId(strs,type);
        this.dict.addArr(id,row);
    }

    /**
     * 添加 语法类型
     */
    iderAddType(strs,type){
        let id= this.addIder(strs)
        let typeId=this.addIder(type)
        let yaccId=this.addIder("语法")
       let row= new Row(id,typeId,yaccId,"")

        this.dict.addArr(id,row);
    }


    /**
     * 获取一个词的ID
     */
    findIderId(strs){
        let ids= this.run(strs)
        return this.lex.findWrodsId(ids[0],ids[1])
    }

/*    /!**
     * 获取一个词的ID
     *!/
    findWord(id){
        let ids= this.run(strs)
        return this.lex.findWrodsId(ids[0],ids[1])
    }*/


}
